import { WuXingGradeUpPanel } from "./WuXingGradeUpPanel";
import { GameConst } from "../../../component/gconst/GameConst";
import { Cache } from "../../cache/Cache";
import { SWuXingDice } from "../../../../Message/Public/SWuXingDice";
import { ExpAddEffect } from "../effect/ExpAddEffect";
import { ExpAddEffectInfo } from "../../resource/info/ExpAddEffectInfo";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { Alert } from "../../../../com/mui/controls/Alert";
import { Language } from "../../../../extend/language/Language";
import { WuXingConfig } from "../../resource/WuXingConfig";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { MsgManager } from "../../manager/MsgManager";
import { EffectManager } from "../../manager/EffectManager";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { ObjCreate } from "../common/ObjCreate";
import { WuXingDiceWordListPanel } from "./dice/WuXingDiceWordListPanel";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { WuXingDiceMaxItem } from "./dice/WuXingDiceMaxItem";
import { TodayNotTipUtil } from "../../../common/TodayNotTipUtil";
import { TodayNoTipsConst } from "../../../component/gconst/TodayNoTipsConst";
import { EActiveType } from "../../../../Message/Public/EActiveType";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { ItemData } from "../../resource/info/ItemData";
import { WuXingRule } from "../../rules/WuXingRule";
import { WuXingPlayerInfo } from "../../model/wuxing/WuXingPlayerInfo";
import { SWFPlayer } from "../../scene/modle/SWFPlayer";
import { ModelType } from "../../scene/modle/data/ModelType";
import { WuxingDiceResultView } from "./dice/WuxingDiceResultView";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class WuXingLevelUpPanel
    
    export  class WuXingLevelUpPanel extends WuXingGradeUpPanel
    {
        constructor(arg1: int=428, arg2: int=438)
        {
            super(arg1, arg2);
            this._wuxingDiceCount = GameConst.WuxingDiceCount;
            this._wuxingFreeChangeCount = GameConst.WuxingFreeChangeCount;
            this._leftJHTimes = this._wuxingDiceCount;
            addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAddToStageHandler);
            if (Cache.instance.role.wuxingInfo) 
            {
                Cache.instance.role.wuxingInfo.isWxDiceSkipAnimation = true;
            }
            return;
        }

        /* internal  */stopAndShowResult(arg1: SWuXingDice): void
        {
            if (!this._throwBtn.visible) 
            {
                this._resultView.visible = true;
                this._resultView.updateBuWuXingDice(arg1);
                this._wordListPanel.updateBuWuXingDice(arg1);
            }
            return;
        }

        public playWuxingValueAddEffect(arg1: int): void
        {
            var loc1=localToGlobal(new Object /* flash.geom.Point */(this._throwBtn.x + this._throwBtn.width / 2, this._throwBtn.y));
            var loc2=localToGlobal(new Object /* flash.geom.Point */(222, 60));
            var loc3;
            (loc3 = new ExpAddEffect(new ExpAddEffectInfo(loc1.x, loc1.y, loc2.x, loc2.y, arg1, 1))).playEffect();
            return;
        }

        protected /* override */ onWuXingBgLoadedHandler(): void
        {
            super.onWuXingBgLoadedHandler();
            this._juhunFont.bitmapData = GlobalClass.getBitmapData(ImagesConst.wxJuHunFont);
            this._levelBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.wxLingZhuLevel);
            return;
        }

        protected /* override */ onOptBtn1ClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            super.onOptBtn1ClickHandler(arg1);
            if (_currentItem) 
            {
                if (_currentItem.wxLevel >= 10 && _currentItem.wxColor < 5) 
                {
                    Alert.buttonWidth = 60;
                    Alert.okLabel = Language.getString(26368);
                    Alert.show(Language.getString(26367), null, Alert.OK | Alert.CANCEL, null, this.onLevelAlertHandler);
                    return;
                }
                if (_info.juhunValue < WuXingConfig.instance.getBaseJuhunValue()) 
                {
                    Alert.buttonWidth = 80;
                    Alert.show(Language.getString(26312), null, Alert.OK | Alert.CANCEL, null, this.onJuHunAlertHandler);
                    return;
                }
                Dispatcher.dispatchEvent(new DataEvent(EventName.WuXingLevelUpReq, _currentItem));
            }
            else 
            {
                MsgManager.showRollTipsMsg(Language.getString(26313));
            }
            return;
        }

        /* internal  */showThrowEffect(arg1: Boolean): void
        {
            if (arg1) 
            {
                EffectManager.glowFilterReg(this._throwBtn, WuXingLevelUpPanel.filterArr, 0.8, 5, 2, 10);
            }
            else 
            {
                EffectManager.glowFilterUnReg(this._throwBtn);
            }
            return;
        }

        protected /* override */ onOptBtn2ClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            super.onOptBtn2ClickHandler(arg1);
            return;
        }

        protected /* override */ initUI(): void
        {
            this._juhunFont = new Object /* flash.display.Bitmap */();
            this._levelBmp = new Object /* flash.display.Bitmap */();
            super.initUI();
            removeChild(_optBtn2);
            _degreeInfo.text = Language.getString(26308) + "：";
            _degreeBar.x = _degreeInfo.x + _degreeInfo.textWidth + 2;
            _optBtn2.toolTipData = HTMLUtil.addColor(Language.getString(26314), "#ffffff");
            this._levelBmp.y = _hLine.y + 8;
            this._levelBmp.x = 90;
            addChild(this._levelBmp);
            this._levelTxt = ObjCreate.createTextField("0/10", 0, _hLine.y + 10, 100, 20, this);
            this._levelTxt.textColor = 16776960;
            this._levelTxt.x = 160;
            _optBtn1.y = _optBtn1.y + 10;
            _optBtn2.y = _optBtn2.y + 10;
            removeChild(_juhunCountBmp);
            _juhunCountBmp.y = _juhunCountBmp.y + 10;
            _juhunCountTxt.y = _juhunCountTxt.y + 10;
            _juhunCountTxt.x = _juhunCountTxt.x - 22;
            this._juhunFont.x = _bg1.x + 165;
            this._juhunFont.y = _quickLookFont.y + 2;
            addChild(this._juhunFont);
            this._juhunValue = ObjCreate.createTextField("0", this._juhunFont.x + 66, this._juhunFont.y, 100, 20, this);
            this._juhunValue.textColor = 16776960;
            this._juhunValue.mouseEnabled = false;
            _line.y = _line.y + 10;
            this._wordListPanel = new WuXingDiceWordListPanel();
            this._wordListPanel.x = 17;
            this._wordListPanel.y = _line.y + 10;
            addChild(this._wordListPanel);
            this._throwBtn = ObjCreate.createGButton(Language.getString(26310), 0, _line.y + 80, 74, 24, this, "ButtonRed");
            this._throwBtn.x = _bg2Width / 2 - this._throwBtn.width / 2;
            this._throwBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onThrowBtnClickHandler);
            this._activeBtn = ObjCreate.createGButton(Language.getStringByParam(26422, 0), 1, this._throwBtn.y, 86, 24, this, "ButtonRed");
            this._activeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onActiveBtnClickHandler);
            ObjCreate.createTextField(Language.getString(26204), 30, _line.y + 115, 200, 20, this, GlobalStyle.textFormat2);
            ObjCreate.createTextField(Language.getString(26205), 123, _line.y + 115, 200, 20, this, GlobalStyle.textFormat2);
            this._dayTimesTxt = ObjCreate.createTextField(this._wuxingDiceCount.toString(), 100, _line.y + 111, 200, 20, this, new GTextFormat(FontUtil.EmbedNumberName, 20, 65280, true));
            this._dayTimesTxt.embedFonts = true;
            this._maxItem = new WuXingDiceMaxItem();
            this._maxItem.x = 240;
            this._maxItem.y = _line.y + 105;
            addChild(this._maxItem);
            this._maxTipTxt = ObjCreate.createTextField("", 173, _line.y + 115, 200, 30, this);
            this._maxTipTxt.mouseEnabled = false;
            return;
        }

        protected onActiveBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._leftActiveTime == 0) 
            {
                MsgManager.showRollTipsMsg(Language.getString(26423));
                return;
            }
            if (Cache.instance.role.money.gold < int(Cache.instance.wuxing.wuxingDiceOneKey.valueStr)) 
            {
                MsgManager.showRollTipsMsg(Language.getString(27957));
                return;
            }
            if (this._resultView.isMax) 
            {
                MsgManager.showRollTipsMsg(Language.getString(26211));
                return;
            }
            TodayNotTipUtil.toDayNotTip(TodayNoTipsConst.ActiveWuXingDiceOneKeyToday, this.goActiveThrow, Language.getStringByParam(26426, Cache.instance.wuxing.wuxingDiceOneKey.valueStr), null, Alert.OK | Alert.CANCEL, null, null, null, 4, true);
            return;
        }

        /* internal  */goActiveThrow(arg1: Boolean): void
        {
            this.throwReq(1, arg1);
            return;
        }

        public updateActiveBtn(): void
        {
            var loc1=Cache.instance.active.isActiveInEffect(EActiveType._EActiveTypeWuxingDiceOneKey);
            this._leftActiveTime = Cache.instance.wuxing.wuxingDiceOneKey.value - Cache.instance.wuxing.wuxingDiceOneKeyUseTimes;
            if (loc1 && !this._throwBtn.visible) 
            {
                this._activeBtn.visible = true;
                this._activeBtn.toolTipData = Language.getStringByParam(26424, Cache.instance.wuxing.wuxingDiceOneKey.valueStr);
                this._activeBtn.label = Language.getStringByParam(26422, this._leftActiveTime);
                if (this._leftActiveTime > 0) 
                {
                    this._activeBtn.enabled = true;
                }
                else 
                {
                    this._activeBtn.enabled = false;
                }
            }
            else 
            {
                this._activeBtn.visible = false;
            }
            return;
        }

        public shineActiveBtn(): void
        {
            var loc1=Cache.instance.active.isActiveInEffect(EActiveType._EActiveTypeWuxingDiceOneKey);
            this._leftActiveTime = Cache.instance.wuxing.wuxingDiceOneKey.value - Cache.instance.wuxing.wuxingDiceOneKeyUseTimes;
            if (loc1 && this._leftActiveTime > 0) 
            {
                EffectManager.glowFilterReg(this._activeBtn, [FilterConst.guideTipsFilter], 0.6, 10, 5, 5);
            }
            return;
        }

        protected /* override */ updateCurrentItem(arg1: ItemData, arg2: Boolean=false): void
        {
            super.updateCurrentItem(arg1, arg2);
            if (arg1) 
            {
                _optItem1.updateData(HTMLUtil.addColor(Language.getString(26316) + _currentItem.wxLevel, "#00ff00"), _currentItem, _currentItem.wxEnergy);
                _optItem2.updateData(HTMLUtil.addColor(Language.getString(26317) + _nextItem.wxLevel, "#00ff00"), _nextItem, _nextItem.wxEnergy);
                this._levelTxt.text = arg1.wxLevel + "/10";
            }
            return;
        }

        protected /* override */ getNextItem(arg1: ItemData): ItemData
        {
            return WuXingRule.getNextGradeItem(arg1, WuXingRule.GradeLevel);
        }

        protected /* override */ updateMaxGradeItem(arg1: ItemData): void
        {
            super.updateMaxGradeItem(arg1);
            _quickLookItemData = WuXingRule.getNextGradeItem(arg1, WuXingRule.GradeLevel, true);
            _quickLookItem.itemData = _quickLookItemData;
            _quickLookItem.toolTipData = _quickLookItemData.getToolTipData();
            return;
        }

        public /* override */ updateJuHunData(arg1: WuXingPlayerInfo): void
        {
            super.updateJuHunData(arg1);
            this._juhunValue.text = arg1.juhunValue.toString();
            return;
        }

        protected /* override */ clear(): void
        {
            super.clear();
            this._levelTxt.text = "0/10";
            return;
        }

        public /* override */ dispose(): void
        {
            super.dispose();
            if (this._juhunSwf) 
            {
                this._juhunSwf.dispose();
            }
            _lastEffectItem = null;
            EffectManager.glowFilterUnReg(_degreeBar);
            return;
        }

        /* internal  */onAddToStageHandler(arg1: Object /* flash.events.Event */): void
        {
            this.initJuHunSwf();
            return;
        }

        protected onJuhunSwfLoaded(arg1: SWFPlayer): void
        {
            this._juhunSwf.timeRate = 10;
            this._juhunSwf.play();
            return;
        }

        protected initJuHunSwf(): void
        {
            if (!this._juhunSwf) 
            {
                this._juhunSwf = new SWFPlayer();
                this._juhunSwf.addEventListener(flash.events.MouseEvent.CLICK, this.onOptBtn2ClickHandler);
            }
            this._juhunSwf.move(_bg1.x + 224, _bg1.y + 90);
            addChild(this._juhunSwf);
            this._juhunSwf.loadComplete = this.onJuhunSwfLoaded;
            this._juhunSwf.load("FriendBlessExpBottleButton.swf", ModelType.NormalSwf, null);
            if (this._juhunSwf.movieClipData) 
            {
                this._juhunSwf.movieClipData.isClear(false);
            }
            return;
        }

        /* internal  */onJuHunAlertHandler(arg1: int): void
        {
            return;
        }

        /* internal  */onLevelAlertHandler(arg1: int): void
        {
            if (Alert.OK == arg1) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.WuXingQuailtyItem, _currentItem));
            }
            return;
        }

        protected /* override */ updateProcessBar(arg1: ItemData): void
        {
            var loc1=0;
            var loc2=null;
            super.updateProcessBar(arg1);
            if (arg1) 
            {
                _degreeBar.setValue(arg1.wxExp, WuXingRule.getExpTotalValue(arg1));
                if (_lastItem && _lastItem.item.uid == arg1.uid && _lastEffectItem && arg1.uid == _lastEffectItem.uid) 
                {
                    if (_degreeBar.totalValue != _lastBarTotal) 
                    {
                        loc1 = _lastBarTotal - _lastBarValue + _degreeBar.value;
                    }
                    else 
                    {
                        loc1 = _degreeBar.value - _lastBarValue;
                    }
                    if (loc1 > 0) 
                    {
                        if (_degreeBar.totalValue != _lastBarTotal) 
                        {
                        };
                        EffectManager.glowFilterReg(_degreeBar, null, 3, 10, 0, 3);
                        _effectEndPoint.x = _degreeBar.x + _degreeBar.width / 2;
                        _effectEndPoint.y = _degreeBar.y;
                        _effectEndPoint = localToGlobal(_effectEndPoint);
                        _effectStartPoint.x = this._juhunSwf.x + 40;
                        _effectStartPoint.y = this._juhunSwf.y + 80;
                        _effectStartPoint = localToGlobal(_effectStartPoint);
                        loc2 = new ExpAddEffect(new ExpAddEffectInfo(_effectStartPoint.x, _effectStartPoint.y, _effectEndPoint.x, _effectEndPoint.y, loc1, 0.5));
                        loc2.playEffect();
                    }
                    loc1 = arg1.wxEnergy - _lastEffectItem.wxEnergy;
                    if (loc1 > 0) 
                    {
                        _optItem1.onGradeEffect();
                    }
                }
            }
            else 
            {
                _degreeBar.setValue(0, 0);
            }
            return;
        }

        /* internal  */throwReq(arg1: int, arg2: Boolean=false): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.WuXingThrowDiceReq, {"type": arg1, "isActive": arg2}));
            return;
        }

        /* internal  */onThrowBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._leftJHTimes == 0) 
            {
                MsgManager.showRollTipsMsg(Language.getString(26221));
                return;
            }
            this.showThrowEffect(false);
            this.throwReq(0);
            return;
        }

        public updateBuWuXingDice(arg1: SWuXingDice, arg2: int=0): void
        {
            if (arg1) 
            {
                this._freeLeftChangeTimes = this._wuxingFreeChangeCount - arg1.toModifyCount;
                this._freeLeftChangeTimes = this._freeLeftChangeTimes > 0 ? this._freeLeftChangeTimes : 0;
                this._leftJHTimes = this._wuxingDiceCount - arg1.throwCount;
                this._dayTimesTxt.text = this._leftJHTimes.toString();
                this._maxTipTxt.htmlText = HTMLUtil.addColor(Language.getStringByParam(26223, arg1.maxDiceNum), this.getMaxColor(arg1.maxDiceNum));
                this._maxItem.maxNum = arg1.maxDiceNum;
                if (arg1.dice.length > 0) 
                {
                    if (!this._resultView) 
                    {
                        this._resultView = new WuxingDiceResultView();
                    }
                    if (!this.contains(this._resultView)) 
                    {
                        this._resultView.x = 17;
                        this._resultView.y = this._throwBtn.y;
                        this._resultView.visible = false;
                        this.addChild(this._resultView);
                    }
                    this._resultView.updateLeftTimeAndModifyCount(arg1.diceMoneyModifyCount, this._freeLeftChangeTimes);
                    this._throwBtn.visible = false;
                    this.updateActiveBtn();
                    this.stopAndShowResult(arg1);
                }
                else 
                {
                    this._wordListPanel.updateBuWuXingDice(arg1);
                    if (this._resultView) 
                    {
                        this._resultView.visible = false;
                    }
                    this._throwBtn.visible = true;
                    this.updateActiveBtn();
                }
                if (this._leftJHTimes == 0) 
                {
                    this.showThrowEffect(false);
                }
            }
            return;
        }

        /* internal  */getMaxColor(arg1: int): string
        {
            var loc1="#00ff00";
            if (arg1 >= 4 && arg1 <= 5) 
            {
                loc1 = "#00BEFF";
            }
            else if (arg1 >= 6 && arg1 <= 9) 
            {
                loc1 = "#FF00FF";
            }
            else if (arg1 >= 10) 
            {
                loc1 = "#FF7902";
            }
            return loc1;
        }

        /* internal */ static /* const */filterArr: Array<any>=[new Object /* flash.filters.GlowFilter */(268435302, 1, 6, 6, 4)];

        protected /* var */_levelBmp: Object /* flash.display.Bitmap */;

        protected /* var */_levelTxt: Object /* flash.text.TextField */;

        protected /* var */_juhunFont: Object /* flash.display.Bitmap */;

        protected /* var */_juhunValue: Object /* flash.text.TextField */;

        /* internal */ /* var */_wordListPanel: WuXingDiceWordListPanel;

        /* internal */ /* var */_resultView: WuxingDiceResultView;

        /* internal */ /* var */_wuxingDiceCount: int;

        /* internal */ /* var */_wuxingFreeChangeCount: int;

        /* internal */ /* var */_freeLeftChangeTimes: int;

        /* internal */ /* var */_leftJHTimes: int;

        /* internal */ /* var */_dayTimesTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_maxItem: WuXingDiceMaxItem;

        /* internal */ /* var */_maxTipTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_throwBtn: GButton;

        /* internal */ /* var */_activeBtn: GButton;

        /* internal */ /* var */_leftActiveTime: int;

        protected /* var */_juhunSwf: SWFPlayer;
    }
